package com.douyu.ocean.recom.platfrom.core.web.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.douyu.ocean.recom.platform.api.model.entiry.RecomBiz;
import com.douyu.ocean.recom.platfrom.core.service.RecomBizService;
import com.douyu.ocean.recom.platfrom.core.web.utils.ControllerUtils;
import com.douyu.ocean.recom.platfrom.core.web.utils.ResultUtils;
import com.douyu.ocean.recom.platfrom.core.web.vo.ResultWrapper;

@RequestMapping("/recom_platform/recomBiz")
@RestController
public class RecomBizController extends BaseController{

	@Resource
	private RecomBizService recomBizService;
	
	@RequestMapping("/create")
	public ResultWrapper<?> create(final RecomBiz record) {
		return ControllerUtils.doHandler(new ControllerUtils.ActionHandler() {

			@Override
			public ResultWrapper<?> getResponse() throws Exception {

				recomBizService.save(record);
				return ResultUtils.asSuccess(record.getId());
			}

		}, "RecomBizController.create");
	}

	@RequestMapping("/queryAll")
	public ResultWrapper<?> queryAll() {

		return ControllerUtils.doHandler(new ControllerUtils.ActionHandler() {

			@Override
			public ResultWrapper<?> getResponse() throws Exception {

				List<RecomBiz> list = recomBizService.queryAllByStatus(1);
				return ResultUtils.asSuccess(list);
			}

		}, "RecomBizController.queryAll");
	}
	
	@RequestMapping("/updateById")
	public ResultWrapper<?> updateById(final RecomBiz record) {

		return ControllerUtils.doHandler(new ControllerUtils.ActionHandler() {

			@Override
			public ResultWrapper<?> getResponse() throws Exception {

				recomBizService.updateById(record);
				return ResultUtils.asSuccess();
			}

		}, "RecomBizController.queryAll");
	}
	
	@RequestMapping("/updateStatusById")
	public ResultWrapper<?> updateStatus(final Long id,final Integer status) {

		return ControllerUtils.doHandler(new ControllerUtils.ActionHandler() {

			@Override
			public ResultWrapper<?> getResponse() throws Exception {
				RecomBiz recomBiz = new RecomBiz();
				recomBiz.setId(id);
				recomBiz.setStatus(status);
				recomBizService.updateById(recomBiz);
				return ResultUtils.asSuccess();
			}

		}, "RecomBizController.queryAll");
	}
	
}
